package com.qd.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdqidi.util.page.PageUtil;
import com.qd.common.sys.domain.entity.msg.MsgReceiveContentDTO;
import com.qd.common.sys.domain.entity.msg.MsgReceiveDTO;
import com.qd.common.sys.domain.entity.msg.MsgReportDTO;
import com.qd.system.service.msg.base.MsgReceiveContentService;
import com.qd.system.service.msg.base.MsgReceiveService;
import com.qd.system.service.msg.base.MsgReportService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * WEB_消息发送
 *
 * @author sjk
 */
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/sys/msgReceive/")
@Slf4j
public class MsgReceiveController {
    private final MsgReceiveService msgReceiveService;
    private final MsgReceiveContentService msgReceiveContentService;
    private final MsgReportService msgReportService;


    /**
     * 详情
     *
     * @param id 主键
     * @return 记录
     */
    @GetMapping(value = "/getById")
    public MsgReceiveDTO getById(@Validated @NotBlank(message = "ID不能为空") String id) {
        return msgReceiveService.getByIdDto(id);
    }

    /**
     * 列表
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/page")
    public IPage<MsgReceiveDTO> page(MsgReceiveDTO dto) {
        return msgReceiveService.page(PageUtil.buildPage(dto), dto);
    }

    /**
     * 内容详情
     *
     * @param id 主键
     * @return 记录
     */
    @GetMapping(value = "/getContentById")
    public MsgReceiveContentDTO getContentById(@Validated @NotBlank(message = "ID不能为空") String id) {
        return msgReceiveContentService.getByIdDto(id);
    }

    /**
     * 回执详情
     *
     * @param msgId 消息ID
     * @return 记录
     */
    @GetMapping(value = "/getReportById")
    public List<MsgReportDTO> getReportByMsgId(@Validated @NotBlank(message = "msgId不能为空") String msgId) {
        return msgReportService.getListByMsgIdDTO(msgId);
    }

}